﻿using LJ.Abstractions.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Linq.Expressions;
using System.Reflection.Metadata;
using System.Security.Principal;

namespace LJ.DataAccess.EntityFrameworkCore;

public class DataAccessDbContext(DbContextOptions<DataAccessDbContext> options, IDataObjectMapManager dataObjectMapManager) : DbContext(options)
{
    private readonly IDataObjectMapManager _dataObjectMapManager = dataObjectMapManager;

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        
        //optionsBuilder.LogTo(Console.WriteLine);
        //optionsBuilder.UseSqlite(ConnectStr);//如果需要别的数据库，在这里进行修改
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        var dataObjectMaps = _dataObjectMapManager.GetDataObjectMaps();

        foreach (var dataObjectMap in dataObjectMaps)
        {
            dataObjectMap.ConfigureDataObjectMap(modelBuilder);
        }

       

    }
}
